import {
  ModalForm,
  ProFormSelect,
  ProFormText,
  ProFormTextArea,
  ProFormRadio,
  ProFormDatePicker,
} from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import React, { PropsWithChildren } from 'react';

interface UpdateFormProps {
  studentCategoryEnum: Map<number, { text: string }>;
  children: any;
}
const CreateForm: React.FC<PropsWithChildren<UpdateFormProps>> = ({
  children,
}) => {
  const { addHandler, qualificationEnum } = useModel(
    'Student.model',
    (model) => ({
      addHandler: model.addHandler,
      qualificationEnum: model.qualificationEnum,
      qualification:model.qualification
    }),
  );

  return (
    <ModalForm<API.Student_Add_Body>
      trigger={children}
      title="新增学生"
      autoFocusFirstInput
      submitTimeout={2000}
      modalProps={{ destroyOnClose: true }}
      onFinish={addHandler}
    >
      <ProFormText
        name="stu_name"
        label="姓名"
        placeholder="请输入学生姓名"
        rules={[
          { required: true, message: '学生姓名为必填项!' },
          { min: 2, max: 20, message: '学生姓名字数在2-20之间!' },
        ]}
      />
      <ProFormRadio.Group
        name="stu_sex"
        label="性别"
        options={[
          { label: '男', value: 1 },
          { label: '女', value: 0 },
        ]}
        rules={[{ required: true, message: '性别为必选项' }]}
      />
      <ProFormText
        name="stu_phone"
        label="联系电话"
        placeholder="请输入手机号码"
        rules={[
          { required: true, message: '手机号码为必填项!' },
          { min: 11, max: 11, message: '请输入11位手机号' },
        ]}
      />
      <ProFormText
        name="stu_phone2"
        label="备用电话"
        placeholder="请输入手机号码"
        rules={[
          { required: true, message: '备用号码为必填项!' },
          { min: 11, max: 11, message: '请输入11位手机号' },
        ]}
      />
      <ProFormDatePicker
        name="stu_born"
        label="出生日期"
        initialValue={'2024-10-28'}
        rules={[{ required: true, message: '出生日期为必选项' }]}
      />
      <ProFormSelect
        name="stu_qualification"
        label="学历"
        placeholder="请选择学历"
        valueEnum={qualificationEnum}
        rules={[{ required: true, message: '学生学历为必选项' }]}
      />
      <ProFormText
        name="stu_school"
        label="毕业院校"
        placeholder="请输入毕业院校"
        rules={[{ required: true, message: '毕业院校为必填项!' }]}
      />
      <ProFormText
        name="stu_major"
        label="专业名称"
        placeholder="请输入专业名称"
        rules={[{ required: true, message: '专业名称为必填项!' }]}
      />
      <ProFormText
        name="stu_address"
        label="家庭住址"
        placeholder="请输入家庭住址"
        rules={[{ required: true, message: '家庭住址为必填项!' }]}
      />

      <ProFormTextArea
        name="stu_remark"
        label="学生备注"
        placeholder="请输入学生备注"
      />
    </ModalForm>
  );
};

export default CreateForm;
